package chances.wechat.repository;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import org.springframework.stereotype.Repository;

import chances.wechat.entity.QrCodeInfo;
import chances.wechat.service.rdb.BaseDao;

@Repository
public class QrCodeRepository extends BaseDao {

	public void insertQrCode(QrCodeInfo qrinfo) {
		Map<String, Object> paramsMap = new HashMap<String, Object>();
		paramsMap.put("obj", qrinfo);
		try {
			this.insert("insertQrInfo", paramsMap);
		} catch(Exception e) {
			e.printStackTrace();
		} finally {
			paramsMap.clear();
			paramsMap = null;
		}
	}

	public QrCodeInfo getQrCodeByQrInfo(String qrInfo) {
		//qrInfo = qrInfo.replaceFirst("qrscene_", "");
		Map<String, Object> paramsMap = new HashMap<String, Object>();
		paramsMap.put("qrInfo", qrInfo);
		try {
			return (QrCodeInfo) this.queryForObject("getQrCodeByQrInfo", paramsMap);
		} catch(Exception e) {
			e.printStackTrace();
		} finally {
			paramsMap.clear();
			paramsMap = null;
		}
		return null;
	}

	public void refreshQrInfo(QrCodeInfo qrInfo) {
		Map<String, Object> paramsMap = new HashMap<String, Object>();
		paramsMap.put("obj", qrInfo);
		try {
			this.update("refreshQrInfo", paramsMap);
		} catch(Exception e) {
			e.printStackTrace();
		} finally {
			paramsMap.clear();
			paramsMap = null;
		}
	}

	public void updateScanTime(String qrInfo) {
		Map<String, Object> paramsMap = new HashMap<String, Object>();
		paramsMap.put("qrInfo", qrInfo);
		paramsMap.put("now", new Date());
		try {
			this.update("updateScanTime", paramsMap);
		} catch(Exception e) {
			e.printStackTrace();
		} finally {
			paramsMap.clear();
			paramsMap = null;
		}
		
	}

}
